package com.fms.dao;

import java.util.List;

import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;

import com.fms.model.Form8Model;

public class Form8DAO {
	
	private SqlSessionFactory sqlSessionFactory; 
	
	public Form8DAO(){
		sqlSessionFactory = MyBatisConnectionFactory.getSqlSessionFactory();
	}
	

	/**
	 * Returns the list of all Form8 instances from the database.
	 * @return the list of all Form8 instances from the database.
	 */
	@SuppressWarnings("unchecked")
	public List<Form8Model> selectAll(){

		SqlSession session = sqlSessionFactory.openSession();
		
		try {
			List<Form8Model> list = session.selectList("Form8.getAll");
			return list;
		} finally {
			session.close();
		}
	}

	/**
	 * Returns a Form8 instance from the database.
	 * @param id primary key value used for lookup.
	 * @return A Form8 instance with a primary key value equals to pk. null if there is no matching row.
	 */
	public Form8Model selectById(int id){

		SqlSession session = sqlSessionFactory.openSession();
		
		try {
			Form8Model form8 = (Form8Model) session.selectOne("Form8.getById",id);
			return form8;
		} finally {
			session.close();
		}
	}

	/**
	 * Updates an instance of Form8 in the database.
	 * @param Form8 the instance to be updated.
	 */
	public void update(Form8Model form8){

		SqlSession session = sqlSessionFactory.openSession();
		
		try {
			session.update("Form8.update", form8);
			session.commit();
		} finally {
			session.close();
		}
	}

	/**
	 * Insert an instance of Form8 into the database.
	 * @param Form8 the instance to be persisted.
	 */
	public void insert(Form8Model form8){

		SqlSession session = sqlSessionFactory.openSession();
		
		try {
			session.insert("Form8.insert", form8);
			session.commit();
		} finally {
			session.close();
		}
	}

	/**
	 * Delete an instance of Form8 from the database.
	 * @param id primary key value of the instance to be deleted.
	 */
	public void delete(int id){

		SqlSession session = sqlSessionFactory.openSession();
		
		try {
			session.delete("Form8.deleteById", id);
			session.commit();
		} finally {
			session.close();
		}
	}
}
